class WeaponItem extends eui.ItemRenderer{
    private item_1:WeaponSmallItem;
    private item_2:WeaponSmallItem;

    private oldData:any;
    constructor()
    {
        super();
        this.skinName = 'weaponItemView';
    }

    public childrenCreated()
    {
        super.childrenCreated();
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.clear, this);
    }

    public dataChanged()
    {
        if(!this.data || this.data == this.oldData)return;
        this.oldData = this.data;
        this.updateUI();
    }

    protected updateUI()
    {
        this.item_1.visible = this.item_2.visible = false;
        for(let i in this.data)
        {
            let index = parseInt(i)+1;
            let data = this.data[i];
            let item:WeaponSmallItem = this['item_'+index];
            item.visible = true;
            item.show(data);
        }
    }

    public clear()
    {
        this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.clear, this);
        this.oldData = null;
    }
}

window['WeaponItem'] = WeaponItem;